package com.matrix.demohx.Service;


import com.easemob.im.ApiClient;
import com.easemob.im.ApiException;
import com.easemob.im.api.UserApi;
import com.easemob.im.api.model.EMCreateUser;
import com.easemob.im.api.model.EMCreateUsersResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserService {

    private UserApi userApi;

    @Autowired
    public UserService(ApiClient apiClient) {
        this.userApi = new UserApi(apiClient);
    }

    public void createUser() {
        List<EMCreateUser> emCreateUserList = new ArrayList<>();
        EMCreateUser createUser = new EMCreateUser();
        createUser.setUsername("userxsy1");
        createUser.setPassword("123");
        emCreateUserList.add(createUser);

        try {
            EMCreateUsersResult result = userApi.createUsers(emCreateUserList);
            // 可以在这里处理成功结果
            System.out.println("User created successfully: " + result);
        } catch (ApiException e) {
            // 处理API异常
            System.err.println("API Exception occurred: " + e.getMessage());
            e.printStackTrace();
            throw new RuntimeException("Failed to create user", e);
        }
    }
}
